/*******************************************************************************
 * Copyright (c) Jerges A. Bello G. 2014. Reservado todos los derechos.
 ******************************************************************************/
package com.jabex.persistence.model;

import java.util.Date;
import java.util.List;

import javax.persistence.*;

import com.jabex.common.to.UserTO;

/**
 * Created with IntelliJ IDEA.
 * User: Jerges Bello
 * Date: 5/11/13
 * Time: 22:28
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "ADA_USER")
public class User extends Identity {
	@Column(name = "USER_NAME", length = 15, unique = false, nullable = false)
	private String userName;
	@Column(name = "NAME", length = 30, unique = false, nullable = false)
	private String name;
	@Column(name = "DOCUMENT_ID", length = 40, unique = true, nullable = false)
	private String documentId;
	@Column(name = "TYPE_DOCUMENT", length = 30, unique = false, nullable = false)
	private String typeDocument;
	@Column(name = "LAST_NAME1", length = 30, unique = false, nullable = false)
	private String lastName1;
	@Column(name = "LAST_NAME2", length = 30, unique = false, nullable = true)
	private String lastName2;
	@Column(name = "EMAIL", length = 50, unique = false, nullable = false)
	private String email;
	@Column(name = "TELEPHONE", length = 50, unique = false, nullable = true)
	private String telephone;
	@Column(name = "SEX", unique = false, nullable = true)
	private Character sex;
	@Column(name = "DATE_BIRTH", unique = false, nullable = true)
	private Date dateBirth;
	@Column(name = "ACTIVE", unique = false, nullable = false)
	private Boolean isActive;
	@Column(name = "TYPE_USER", unique = false, nullable = true)
	private String typeUser;
	@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
	private Security security;
	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
	private List<Rol> rolList;

	public User() {
	}

	public User(UserTO userTO) {
		if(userTO.getCode() != null) {
			this.setId(userTO.getCode());
		}
		this.userName = userTO.getUserName();
		this.name = userTO.getName();
		this.documentId = userTO.getDocumentId();
		this.typeDocument = userTO.getTypeDocument();
		this.lastName1 = userTO.getLastName1();
		this.lastName2 = userTO.getLastName2();
		this.email = userTO.getEmail();
		this.telephone = userTO.getTelephone();
		this.sex = userTO.getSex();
		if (userTO.getDataBirth() != null) {
			this.dateBirth = userTO.getDataBirth().toDate();
		}
		this.isActive = userTO.getIsActive();
		this.typeUser = userTO.getTypeDocument();
	}

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public String getDocumentId() {
		return documentId;
	}

	public void setDocumentId(String documentId) {
		this.documentId = documentId;
	}


	public String getTypeDocument() {
		return typeDocument;
	}

	public void setTypeDocument(String typeDocument) {
		this.typeDocument = typeDocument;
	}


	public String getLastName1() {
		return lastName1;
	}

	public void setLastName1(String lastName1) {
		this.lastName1 = lastName1;
	}


	public String getLastName2() {
		return lastName2;
	}

	public void setLastName2(String lastName2) {
		this.lastName2 = lastName2;
	}


	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}


	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}


	public Character getSex() {
		return sex;
	}

	public void setSex(Character sex) {
		this.sex = sex;
	}

	public Date getDateBirth() {
		return dateBirth;
	}

	public void setDateBirth(Date dateBirth) {
		this.dateBirth = dateBirth;
	}

	public List<Rol> getRolList() {
		return rolList;
	}

	public void setRolList(List<Rol> rolList) {
		this.rolList = rolList;
	}


	public Boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}


	public Security getSecurity() {
		return security;
	}

	public void setSecurity(Security security) {
		this.security = security;
	}


	public String getTypeUser() {
		return typeUser;
	}

	public void setTypeUser(String typeUser) {
		this.typeUser = typeUser;
	}
}
